Stack memory is an area of memory allotted for automatic variables. Automatic variables are allocated and de-allocated automatically when program flow enters and leaves the variable's scope. Stack memory is allocated and de-allocated at the top of the stack, using Last-In-First-Out (LIFO). Because of this process, stack allocation is simpler and typically faster than heap allocation.
Heap memory is set aside for dynamic allocation. Unlike the stack, there's no enforced pattern to the allocation and de-allocation of blocks from the heap; you can allocate a block at any time and free it at any time. This makes it much more complex to keep track of which parts of the heap are allocated or free at any given time.
Furthermore, allocating and de-allocating many small blocks may leave the heap in a state where there are a lot of small free blocks interspersed between the used blocks. Consequently, a request to allocate a large block may fail because none of the free blocks are large enough to satisfy the allocation request even though the combined size of the free blocks may be large enough. This is what is referred to as heap fragmentation.
In languages like C and C++, data stored on the heap can be deleted manually by the programmer using one of the built in keywords like free, delete, or delete[ ]. Other languages like Java and .NET can use garbage collection to automatically delete memory from the heap without the programmer having to do anything. On the other hand, data on the stack can be automatically de-allocated when variables go out of scope.